package view;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;

/**
 * This class contains the patient entry tab, used as a component in the main GUI.
 * @author Audun
 *
 */

public class PatientTab extends JSplitPane {
	
	private JTextArea patientInfoArea;
	private JList list;
	private JSplitPane splitPane;
	private JButton diagnosisSearchButton;
	private JTable patientInfoTable;
	private JPanel patientInfoPanel;

	public PatientTab(String[] patientEntries) {
		super(JSplitPane.HORIZONTAL_SPLIT);
		setOneTouchExpandable(true);
		setDividerLocation(70);
		initiateComponents(patientEntries);
	}

	private void initiateComponents(String[] patientEntries) {		
			patientInfoPanel = new JPanel();
			patientInfoArea = new JTextArea();
			diagnosisSearchButton = new JButton("Patient diagnosis info");
			JScrollPane patientInfoScrollPane = new JScrollPane(patientInfoArea);
			
			patientInfoArea.setColumns(20);
			patientInfoArea.setLineWrap(true);
			patientInfoArea.setRows(5);
			patientInfoArea.setWrapStyleWord(true);
			patientInfoArea.setEditable(false);
			
			patientInfoPanel.setLayout(new BorderLayout());
			patientInfoPanel.add(patientInfoScrollPane, BorderLayout.CENTER);
			patientInfoPanel.add(diagnosisSearchButton, BorderLayout.SOUTH);
			
			list = new JList(patientEntries);
			list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			list.setSelectedIndex(0);
			
			JScrollPane patientIDPane = new JScrollPane(list);
			
			Dimension minimumSize = new Dimension(100,50);
			patientIDPane.setMinimumSize(minimumSize);
			
			setLeftComponent(patientIDPane);
			setRightComponent(patientInfoPanel);
	}
	
	public int stemOrNot() {
		Object[] methods = { "Exact word matching", "Stemmed" };
		int n = JOptionPane.showOptionDialog(this, "Which search method would you like ?", "Search Method",
				JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, methods, methods[0]);
		return n;
	}

	public JList getList() {
		return list;
	}

	public void setText(String string) {
		patientInfoArea.setText(string);
	}

	public JTextArea getPatientInfoArea() {
		return patientInfoArea;
	}
	
	public JButton getDiagnosisSearchButton() {
	return diagnosisSearchButton;
}
}